package org.apache.rocketmq.example.kang.product.tags;

import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.example.Order;
import org.apache.rocketmq.example.kang.KangConfig;

/**
 * 生产带tag消息
 */
public class ProducerTagsDemo {

    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("dw_test_producer_group");
        producer.setNamesrvAddr(KangConfig.NAMESRV_ADDR);
        producer.start();
        // 订单实体
        Order order = new Order();
        order.setId(1001L);
        order.setOrderNo("2020072823270500003");
        order.setBuyerId(1L);
        order.setSellerId(2L);
        order.setTotalPrice(10000L);
        order.setStatus(0);
        Message msg = new Message("dw_test", "c", "2020072823270500003",
                JSON.toJSONString(order).getBytes());
        System.out.printf("%s%n", producer.send(msg));
        order.setStatus(1);
        msg = new Message("dw_test", "w", "2020072823270500003",
                JSON.toJSONString(order).getBytes());
        System.out.printf("%s%n", producer.send(msg));
        // shutdown 会导致 rocketmq-dashboard#message#TOPIC查询时异常
        //producer.shutdown();
    }

}
